#!/bin/bash

# Prepare the AppDir Data 
mkdir -p output
cd output
mkdir AppDir
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin.com.qq.office/deepin.com.qq.office_2.0.0deepin4_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/u/udis86/udis86_1.72-2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-fonts-wine_2.18-18~rc2_all.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-libwine-dbg_2.18-18~rc2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-libwine-dev_2.18-18~rc2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-libwine_2.18-18~rc2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-wine-binfmt_2.18-18~rc2_all.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-wine32-preloader_2.18-18~rc2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-wine32-tools_2.18-18~rc2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-wine32_2.18-18~rc2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine/deepin-wine_2.18-18~rc2_all.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine-plugin/deepin-wine-plugin_1.0deepin2_amd64.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine-plugin/deepin-wine-plugin_1.0deepin2_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine-helper/deepin-wine-helper_1.2deepin0_i386.deb
wget -c http://packagess.deepin.com:8081/deepin/pool/non-free/d/deepin-wine-uninstaller/deepin-wine-uninstaller_0.1deepin2_i386.deb
wget -c http://mirrors.edge.kernel.org/ubuntu/pool/universe/u/unionfs-fuse/unionfs-fuse_1.0-1ubuntu2_amd64.deb
ls *.deb | awk -va="AppDir" '{print $1,a}' | xargs -n2 dpkg-deb -x
mkdir -p AppDir/Deepin-TIM
7z x AppDir/opt/deepinwine/apps/Deepin-TIM/files.7z -oAppDir/Deepin-TIM/
mkdir -p AppDir/Temp
rm AppDir/opt/deepinwine/apps/Deepin-TIM/files.7z

# Add some run script to Appdir
cp -r ../Addition/AppRun ./AppDir/AppRun
cp -r ../Addition/deepintim.desktop ./AppDir/deepinim.desktop
cp -r ../Addition/proot-130 ./AppDir/proot-130
cp -r ../Addition/runtim ./AppDir/runtim
cp -r ../Addition/TIM.png ./AppDir/TIM.png
cp -r ../Addition/runtim-proot ./AppDir/runtim-proot
cp -r ../Addition/simsun.ttc ./AppDir/Deepin-TIM/drive_c/windows/Fonts/simsun.ttc

chmod +x AppDir/AppRun AppDir/proot-130 AppDir/runtim AppDir/runtim-proot




# Use Appimagetool to produce the appimage
wget -c "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod +x appimagetool-x86_64.AppImage
ARCH=x86_64 ./appimagetool-x86_64.AppImage AppDir/ 
